package b2.widget.fort
{
	import b2.config.*;
	import b2.net.*;
	import b2.player.*;
	import b2.scene.*;
	import b2.util.*;
	import b2.widget.*;
	import b2.widget.tab.*;
	
	import com.smartfoxserver.v2.entities.*;
	import com.smartfoxserver.v2.requests.*;
	
	import flash.display.Sprite;
	import flash.events.*;
	import flash.filters.*;
	import flash.text.*;
	import flash.ui.Mouse;
	
	public class RoomItem extends Sprite
	{
		private var room:Room;
		
		public function RoomItem(room:Room = null)
		{
			this.room = room;
			//背景框
			var RoomItemBgr:Class = ResourceHelper.getInstance().getClassByName("RoomItemBgr");
			var roomItemBgr:Sprite = new RoomItemBgr();
			roomItemBgr.alpha = 0.5;
			addChild(roomItemBgr);
			//房间号
			if (room != null)
			{
				var titleText:TextField = new TextField();
				titleText.selectable = false;
	        	titleText.autoSize = TextFieldAutoSize.LEFT;
				titleText.defaultTextFormat = new TextFormat("微软雅黑", 13, 0xFFFFFF);
				titleText.filters = [new GlowFilter(0x000000, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
				titleText.x = 8;
				titleText.y = 3;
				titleText.htmlText = "<font color='#FFFF00'>房间号:</font>  " + room.name;
				addChild(titleText);
				//房主
				var playerId:String = room.name.substr(0, room.name.length - 4);
				var user:User = SmartFoxHelper.getInstance().sfs.userManager.getUserByName(playerId);
				if (user != null)
				{
					var ownerText:TextField = new TextField();
					ownerText.selectable = false;
		        	ownerText.autoSize = TextFieldAutoSize.LEFT;
					ownerText.defaultTextFormat = new TextFormat("微软雅黑", 13, 0xFFFFFF);
					ownerText.filters = [new GlowFilter(0x000000, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
					ownerText.x = 8;
					ownerText.y = 23;
					ownerText.htmlText = "<font color='#FFFF00'>房主:</font>  " + user.getVariable("playerName").getStringValue();
					addChild(ownerText);
				}
			}
			this.mouseChildren = false;
			this.doubleClickEnabled = true;
			addEventListener(MouseEvent.CLICK, onMouseClick);
			addEventListener(MouseEvent.DOUBLE_CLICK, onMouseDoubleClick);
			addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
		}

		private function onMouseDoubleClick(event:MouseEvent):void
		{
			//加入房间
			if (room != null)
			{
				SmartFoxHelper.getInstance().joinRoom(room.name);
			}
//			//创建房间
//			else
//			{
//				var fortressDialog:FortressDialog = WidgetManager.getInstance().currentFortressDialog;
//				if (fortressDialog != null)
//				{
//					SmartFoxHelper.getInstance().createRoom(fortressDialog.currentSelectedCampItem.campIndex);
//				}
//			}
		}
		
		private function onMouseClick(event:MouseEvent):void
		{
		}

		private function onMouseOver(event:MouseEvent):void
		{
			Mouse.cursor = "button";
			this.filters = [new ColorMatrixFilter(BFont.brightFilter)];
		}
		
		private function onMouseOut(event:MouseEvent):void
		{
			Mouse.cursor = "auto";
			this.filters = null;
		}
		
	}
}